﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToursAgencyDAL;

namespace TourAgency.Admin
{
    public partial class Transport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var transports = ToursAgencyDataFuncs.GetAllTransports();
            this.gridViewTransports.DataSource = transports;
            this.gridViewTransports.DataBind();
            Session["transports"] = transports;
        }

        protected void gridViewDestinations_PageIndexChanged(object sender, GridViewPageEventArgs e)
        {
            this.gridViewTransports.PageIndex = e.NewPageIndex;
            this.gridViewTransports.DataSource = Session["transports"];
            this.gridViewTransports.DataBind();
        }

        protected string EncodeTransportName(string property)
        {
            string name = (string)Eval(property);
            string encodedName = Server.HtmlEncode(name);
            return encodedName;
        }

        protected void DeleteTransport(object sender, CommandEventArgs e)
        {
            int id = int.Parse(e.CommandArgument.ToString());
            ToursAgencyDAL.Transport transport = new ToursAgencyDAL.Transport();
            transport.ID = id;
            ToursAgencyDataFuncs.DeleteTransport(transport);
            var transports = ToursAgencyDataFuncs.GetAllTransports();
            this.gridViewTransports.DataSource = transports;
            this.gridViewTransports.DataBind();
            Session["transports"] = transports;
        }

        protected void EditTransport(object sender, CommandEventArgs e)
        {
            Session["editTransport"] = int.Parse(e.CommandArgument.ToString());
            Response.Redirect("~/Admin/Modify/EditTransport.aspx");
        }
    }
}